﻿using NUnit.Framework;
using Vk.Authorization;

namespace UnitTests
{
    public abstract class TestsAuthBase : TestsBase
    {
        private const int AppId = 3281760;
        private const string Login = "harabar.vl@yandex.ua";
        private const string Password = "B575QNhLL7g3";

        private ApiAccessPermissions Permissions { get; }
        protected VkSession Session { get; private set; }

        public TestsAuthBase(ApiAccessPermissions permissions)
        {
            Permissions = permissions;
            GetSession();
        }

        private void GetSession()
        {
            var hiddenAuth = new HiddenAuth(AppId, Permissions);
            hiddenAuth.AuthSuccess += (obj, args) =>
            Session = args.Session;
            hiddenAuth.AuthFail += (obj, args) => Assert.Fail("Couldn't authorize");

            hiddenAuth.AuthAsync(Login, Password).Wait(30000);
        }
    }
}
